﻿
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return (r[2]); return null;
}


//---------------------------------------------------------------
//ServiceNotice.aspx
//---------------------------------------------------------------
var NoticeInfo = new Array();
function addNotice() {
    var NoticeIndex = NoticeInfo.length - 1;
    for (var i = 0; i < 6; i++) {
        NoticeInfo.push("<li><a href='#'><span>您有未审核的商品</span></a></li>")
    }
    bindSnList();
}
function bindSnList() {
    for (var i = 0; i < NoticeInfo.length; i++) {
        $("#sn_list").append(NoticeInfo[i]);
    }
    window.parent.iFrameHeight();
}

//---------------------------------------------------------------
//Default.aspx
//---------------------------------------------------------------

function iFrameHeight() {
    var ifm = document.getElementById("info_page");
    var subWeb = document.frames ? document.frames["info_page"].document : ifm.contentDocument;
    if (ifm != null && subWeb != null) {
        ifm.height = subWeb.body.scrollHeight;
    }
    ifm.height = $("#info_page").contents().find("body").height();
}

function iFrameSrc(src) {
    if ($('#info_page').attr("id") == undefined) {
        window.location.href = src;
        return;
    } else {
        $('#info_page').removeClass().addClass('fadeOut animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
            $(this).attr('src', src);
            document.getElementById("info_page").onload = function () {
                var ifm = document.getElementById("info_page");
                var subWeb = document.frames ? document.frames["info_page"].document : ifm.contentDocument;
                if (ifm != null && subWeb != null) {
                    ifm.height = subWeb.body.scrollHeight;
                }
                ifm.height = $("#info_page").contents().find("body").height();
                $('#info_page').removeClass().addClass('fadeIn animated');
            };
        });

    }
}


//---------------------------------------------------------------
//Login.aspx
//---------------------------------------------------------------
function userLogin() {
    var Account = new Object();
    Account.Acc_Name = $("#txt_UserName").val();
    Account.Acc_Pass = $("#txt_PassWord").val();
    Account.Acc_Remember = document.getElementById("remember").checked;
    if (Account.Acc_Name == "") {
        $("#login_error").text("用户名不能为空");
        return false;
    }
    if (Account.Acc_Pass == "") {
        $("#login_error").text("密码不能为空");
        return false;
    }
    $.ajax({
        url: "Login.aspx",
        data: Account,
        type: "post",
        datatype: "text",
        success: function (data) {
            if (data != "true")
                $("#login_error").text(data);
            else
                window.location.href = "Default.aspx";
        }
    });
}

//---------------------------------------------------------------
//ProductLaunch.aspx
//---------------------------------------------------------------
function uploadSuccessImg(msg) {
    if (msg.split('|').length > 2) {
        $('#upload' + msg.split('|')[0]).css('background', "url('" + msg.split('|')[2] + "') no-repeat 100%");
        $('#ProductImg' + msg.split('|')[0]).val(msg.split('|')[2]);
        $('#Info1_ImgUrl' + msg.split('|')[0]).val(msg.split('|')[2]);
        $('#UploadLogImg' + msg.split('|')[0]).html(msg.split('|')[1]);
    } else {
        $('#UploadLogImg' + msg.split('|')[0]).html(msg.split('|')[1]);
    }
}
function fileClick(obj) {
    document.getElementById("FileUpImg" + obj).click();
}
function upload(obj) {
    if ($('#FileUpImg' + obj).val() == "")
        return;
    $('#UploadLogImg' + obj).html('开始上传中....');
    $('#FormUpImg' + obj).submit();
}
function submitProduct(push_approval) {
    var Type = GetQueryString("type");
    var Push = new Object();
    Push.Push_Name = $("#txt_Name").val();
    Push.Push_Msg = $("#txt_Msg").val();
    Push.Push_Type = $("#txt_Type").val();
    Push.Push_ImgPath = $("#ProductImg1").val() + "-" + $("#ProductImg2").val() + "-" + $("#ProductImg3").val() + "-" + $("#ProductImg4").val();
    Push.Push_Approval = push_approval;
    Push.Push_Active = "DeActed";
    Push.Edit = Type;
    Push.Push_ID = GetQueryString("ID");
    Push.Push_Prod_ID = $("#txt_Prod_ID").val();
    $.ajax({
        url: "../SMHandler/SubmitProduct.ashx",
        data: Push,
        type: "post",
        datatype: "text",
        success: function (data) {
            if (data == "true") alert("操作成功！"); else alert("操作失败！");
        }
    });
}